﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WaterBill.DTO;

namespace WaterBill.DAL
{
    class DAL_Database :clsConnection
    {
        public void DAL_Database_Dispose()
        {
            try
            {
                Dispose();
            }
            catch
            {
            }
        }
        public Boolean DAL_Database_Backup(string path)
        {
            try
            {
                AddParameter(new SqlParameter("@path", path));
                if (ExcuteNonQuery("Backupdatabase"))
                {
                    return true;
                }
            }
            catch (Exception)
            {
            }
            return false;
        }

        public Boolean DAL_Database_Restore(string path)
        {
            try
            {
                if (RestoreDatabase(path))
                {
                    return true;
                }
            }
            catch (Exception)
            {
            }
            return false;
        }

        public Boolean DAL_Database_checkConnectServer(string ServerName)
        {
            try
            {
                if (checkConnectServer(ServerName))
                {
                    return true;
                }
            }
            catch
            {
            }
            return false;
        }

        public Boolean DAL_Database_settingConnection(string ServerName, string DatabaseName)
        {
            //try
            //{
                if (settingConnection(ServerName, DatabaseName))
                {
                    return true;
                }
            //}
            //catch
            //{
            //}
            return false;
        }

        public Boolean DAL_Database_checkExistFileSinfo()
        {
            try
            {
                if (checkExistFileSinfo())
                {
                    return true;
                }
            }
            catch
            {
            }
            return false;
        }

        public Boolean DAL_Database_checkNotExistDatabase(string ServerName = null, string DatabaseName = null)
        {
            try
            {
                if (checkNotExistDatabase(ServerName, DatabaseName))
                {
                    return true;
                }
            }
            catch
            {
            }
            return false;
        }

        public List<DTO_InfoConnect> DAL_Database_GetListServer()
        {
            List<DTO_InfoConnect> InfoConnect = new List<DTO_InfoConnect>();
            try
            {
                InfoConnect = GetListServerName();
            }
            catch
            {
            }
            return InfoConnect;
        }

        public List<DTO_InfoConnect> DAL_Database_GetListDatabase(string ServerName)
        {
            List<DTO_InfoConnect> InfoConnect = new List<DTO_InfoConnect>();
            try
            {
                InfoConnect = GetListDatabase(ServerName);
            }
            catch
            {
            }
            return InfoConnect;
        }

    }
}
